const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    filename: 'chunk-[contenthash].js',
    path: path.join(__dirname, 'dist')
  },
  module: {
    rules: [{
        test: /\.vue$/,
        use: [
          'vue-loader',
          'eslint-loader'
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          'babel-loader',
          'eslint-loader'
        ]
      },
      {
        test: /\.css$/,
        use: [
          // style-loader vue-style-loader都可以
          // vue-style-loader做了一些服务端渲染的优化
          // vue-style-loader需要设置css-loader esModule:false
          'vue-style-loader',
          // 'style-loader',
          {
            loader: 'css-loader',
            options: {
              esModule: false
            }
          },
        ]
      },
      {
        test: /\.less$/,
        use: [
          'vue-style-loader',
          // 'style-loader',
          {
            loader: 'css-loader',
            options: {
              esModule: false
            }
          },
          'less-loader'
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10 * 1024,
            // 未设置时图片src = "[object Module]"
            // 与vue-loader导出方式有关
            esModule: false 
          }
        }
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      template: './public/index.html',
      title: 'vue-project'
    }),
    new webpack.DefinePlugin({
      BASE_URL: JSON.stringify('./')
    })
  ]
}